
#include "zos_config.h"


#ifdef BOARD_USING_I2C_DEMO
#include  "zos.h"
//任务全局变量
zos_task_t  demo_i2c_task_handle = NULL;

/**
 * @brief 任务线程
 */
int demo_i2c(int argc, char *argv[])
{
	zos_uint8_t rxdata[9] = {};
	zos_uint8_t reg;
	zos_uint16_t devaddress = 0x23;
	ZOS_I2C_CONFIG i2c_cfg;
	zos_uint8_t mode;
	i2c_cfg.mode=ZOS_I2C_MODE_MASTER;
	i2c_cfg.speed=ZOS_I2C_SPEED_100K;
	mode=zos_i2c_init(ZOS_I2C_BUS_0,&i2c_cfg);

	if(mode == ZOS_EOK)
	{
		reg=0x01;
		zos_i2c_write(ZOS_I2C_BUS_0,devaddress,&reg,1);
		reg=0x07;
		zos_i2c_write(ZOS_I2C_BUS_0,devaddress,&reg, 1);
		reg=0x11;
		zos_i2c_write(ZOS_I2C_BUS_0,devaddress,&reg, 1);
		zos_i2c_read(ZOS_I2C_BUS_0,devaddress,rxdata,2);
		zos_printf("light is %d   %d\r\n",rxdata[0],rxdata[1]);
		return ZOS_EOK;
	}
	else
	{
		zos_printf("I2C_INIT ERROR\r\n");
		return ZOS_ERROR;
	}
		
}

#include "shell.h"

SHELL_EXPORT_CMD(demo_i2c,demo_i2c, i2c demo);


#endif //DEMO_TEST
